:Init

@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@pushd %~dp0
@prompt $_
@echo off

if "%1" == "" goto Usage
if "%2" == "" goto Usage
if not exists "%2" goto Usage
goto Attach

:Usage
@echo.
@echo Mounts a virtual hard drive (VHD) file to the provided drive letter.  
@echo.
@echo MOUNTDRIVE letter [drive:][path]filename
@echo.
@echo   letter      The drive letter to assign to the volume.
@echo.
@echo   [drive:][path][filename]
@echo               Specifies the full path the VHD file to mount.
@echo
@goto End

:CheckPaths
if exists "%1" (
    @echo Drive letter '%1' already in use.
    @goto End
)
if not exists "%2" (
    @echo Unable to locate virtual hard drive file at '%2'.
    @goto End
)

:Attach
@echo select vdisk file="%2%" > "%TEMP%\accelcon.attachvhd.script.txt"
@echo assign letter=%_1% >> "%TEMP%\accelcon.attachvhd.script.txt"
@echo attach vdisk >> "%TEMP%\accelcon.attachvhd.script.txt"
@diskpart.exe -s "%TEMP%\accelcon.attachvhd.script.txt"
@ping 1.0.0.0 -n 5 -w 1000 >NUL

REM ~~( END )~~
@echo.
@echo Completed.
@echo.
:End